import type LayerModelSimple from '../../LayerModel/LayerModelSimple'
import { GeoView } from '../../type/GeoType'
import MapUtil from '../../utils/MapUtil'
import { Map } from 'leaflet'

/**
 * @ClassName LeafletMapUtil
 * @Description Leaflet地图工具
 * @Author xuyizhuo
 * @Date 2023/11/16 22:14
 */
export default class LeafletMapUtil extends MapUtil<Map> {
    /**
     * 加载地图服务
     * @returns {}
     */
    addService(): LayerModelSimple<Map> {
        return {} as LayerModelSimple<Map>
    }

    /**
     * 获取地图视角
     * @returns {}
     */
    getMapView(): GeoView {
        // 获取地图中心点和地图层级
        const map = this.realMap
        const centerPoint = map.getCenter()
        return <GeoView>{
            x: centerPoint.lng,
            y: centerPoint.lat,
            z: map.getZoom() + 1,
        }
    }

    /**
     * 飞行到视角
     * @param {GeoView} geoView 视角信息
     * @returns {LeafletMapUtil}
     */
    flyToView(geoView: GeoView): LeafletMapUtil {
        // 设置地图中心点和层级
        const { x, y, z } = geoView
        this.realMap.setView({ lng: x, lat: y }, z - 1)
        return this
    }
}
